﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BaiTapThucHanh.aspx.cs" Inherits="JavaScript_Demo_BaiTapThucHanh" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script language="javascript" type="text/javascript">
    function select_nguoilon() {
    
        var selectNguoilonValue = document.form1.drpnguoilon.value;
        var selectTreemValue = 20 - (selectNguoilonValue * 2);
        
        var i;
        var j;

        removeSelectTreEmOption();

        for (i = 1; i <= selectTreemValue; i++) {
        
            document.getElementById('drptreem').options[i] = new Option(i, i)
            document.getElementById('drptreem').selectedIndex = selectTreemValue;
        }

        function removeSelectTreEmOption() {
            
            var i;
            for (i = 0; i < document.form1.drptreem.options.length; i++) {
                document.form1.drptreem.remove(i);
            }
        }
    }

    function select_treem() {

        var TreemValue = document.form1.drptreem.value;
        var NguoilonValue = 20 - Math.round(TreemValue / 2);

        var i;
        var j;

        removeSelectNguoilonOption();

        for (i = 1; i <= NguoilonValue; i++) {

            document.getElementById('drpnguoilon').options[i] = new Option(i, i)
            document.getElementById('drpnguoilon').selectedIndex = NguoilonValue;
        }

        function removeSelectNguoilonOption() {

            var i;
            for (i = 0; i < document.form1.drpnguoilon.options.length; i++) {
                document.form1.drpnguoilon.remove(i);
            }
        }

    }


    
</script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Số phòng đặt : <asp:DropDownList ID="drpsophong"  runat="server"></asp:DropDownList>
        <br />
        Số Người lớn: <asp:DropDownList ID="drpnguoilon" runat="server" onchange="select_nguoilon(this.value)" > </asp:DropDownList>
        Trẻ em : <asp:DropDownList ID="drptreem" runat="server" onchange="select_treem(this.value)"></asp:DropDownList>
        
    </div>
    </form>
</body>
</html>
